package org.example.everyday;

import java.util.Arrays;

public class Lc899 {
    public static void main(String[] args) {
        Lc899 lc899 = new Lc899();

    }

    public String orderlyQueue(String s, int k) {
        if(k == 1){
            String smallest = s;
            StringBuilder sb = new StringBuilder(s);
            int n = s.length();
            for(int i = 1; i < n; i++){
                char c = sb.charAt(0);
                sb.deleteCharAt(0);
                sb.append(c);
                if(sb.toString().compareTo(smallest) < 0){
                    smallest = sb.toString();
                }
            }
            return smallest;
        } else {
            char[] arr = s.toCharArray();
            Arrays.sort(arr);
            return new String(arr);
        }
    }
}
